package app.projeto.session;

import app.projeto.dao.Dao;

public class Session {

	protected Dao dao;
	
	public Session(Dao dao) throws Exception {
		this.dao = dao;
	}
	
	public Object save(Object obj) throws Exception {
		this.dao.save(obj);
		this.dao.commit();
		return this.find(obj);		
	}

	//objId: objeto com o id que desejo remover
	//objFind: objeto com os filtros de busca
	public Object[] removeList(Object objId, Object objFind) throws Exception {
		if (this.delete(objId) == null) {
			return null;
		}
		//Refaz a consulta (com os filtros) sem o objeto que foi removido
		return find(objFind);
	}
	
	public Object delete(Object obj) throws Exception {
		this.dao.delete(obj);		
		this.dao.commit();
		return obj;
	}

	public Object[] find(Object obj) throws Exception {
		return this.dao.find(obj);
	}
	
	public Object detail(Object obj) throws Exception {
		return this.findByPrimaryKey(obj);
	}

	public Object findByPrimaryKey(Object obj) throws Exception {
		return this.dao.findByPrimaryKey(obj);
	}
	
	public Object[] print(Object obj) throws Exception {
		return this.find(obj);
	}
	
//	public Object[] removeList(Object objId, Object objFind) throws Exception {
//	this.delete(objId);
//	return this.find(objFind);
//}
	
//	public Object delete(Object obj) throws Exception {
//	this.dao.delete(obj);
//	this.dao.commit();
//	return obj;
//}
}
